package com.fage.beananno;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.concurrent.TimeUnit;

/**
 * @author lin
 * @version 1.0
 * @date 2021/4/11 13:59
 * @Description TODO
 */
@Component
public class Car implements BeanPostProcessor, InitializingBean, DisposableBean {

    @PostConstruct
    public void initMethod() {
        System.out.println("initMethod。。。");
    }

    @PreDestroy
    public void destroyMethod() {
        System.out.println("destroyMethod。。。");
    }

    public void doTask() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行任务结束");
    }

        @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet。。。");
    }

       @Override
    public void destroy() {
        System.out.println("afterPropertiesSet。。。");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization。。。" + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization。。。" + beanName);
        return bean;
    }
}
